﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DCSLibrary;
using Utils.DatabaseUtils;
using Utils.DC.Web.UI;
using Telerik.Web.UI;

public partial class quan_tri_trang_nhom : System.Web.UI.UserControl
{
    #region Cac bien dung chung
    CategoryPageUI objCategoryPage = new CategoryPageUI();
    DataSet dsCategoryPage;

    #endregion

    #region Cac Ham Su Kien

    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!IsPostBack)
        {
            BindGrid();
        }
    }

    protected void CategoryPage_Edit(object sender, EventArgs e)
    {
        LinkButton link = (LinkButton)sender;
        //LoadEditData(Convert.ToInt32(link.CommandArgument));
    }

    protected void grd_PageIndexChanged(object source, GridPageChangedEventArgs e)
    {
        BindGrid();
    }

    protected void CategoryPage_Delete(object source, GridCommandEventArgs e)
    {
        try
        {
            int id = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.Items[e.Item.ItemIndex]["CategoryPageID"].Text.ToString());
            int result = objCategoryPage.DeleteByID(id);
            if (result > 0)
            {
                //Response.Write(messageBox.Alert(MessageBox.MESSAGE_ADD_SUCCESSFULLY));
                lblMessage.Text = MessageBox.MESSAGE_DELETE_SUCCESSFULLY;
                BindGrid();
            }
            else
            {
                //Response.Write(messageBox.Alert(MessageBox.MESSAGE_ADD_NOT_SUCCESSFULLY));
                lblMessage.Text = MessageBox.MESSAGE_DELETE_NOT_SUCCESSFULLY;
            }
        }
        catch (Exception ex)
        {
            lblMessage.Text = MessageBox.MESSAGE_CONFILCT_DATA;
            BindGrid();
        }
    }

    protected void Ajax_Request(object sender, AjaxRequestEventArgs e)
    {
        if (e.Argument == "Rebind")
        {
            dsCategoryPage = objCategoryPage.GetAll();
            BindGrid();
        }
    }

    #endregion

    #region Cac Ham Tuong Tac Du Lieu

    private void BindGrid()
    {
        dsCategoryPage = objCategoryPage.GetAll();
        grdCategoryPage.DataSource = dsCategoryPage.Tables[0];
        grdCategoryPage.DataBind();
    }

    
    #endregion

    

}
